package odgs.message.server;

import odgs.Connection;
import odgs.ExplorerNode;
import odgs.Result;
import odgs.message.Message;
import odgs.message.MessageHandler;
import odgs.message.MessageProcessor;
import odgs.transaction.MoveTransaction;

public class MoveRequestTransactionHandler implements MessageHandler
{
	public void execute(MessageProcessor processor, Message msg, Connection con)
	{
		MoveTransaction tran = (MoveTransaction) msg.get("transaction");
		ExplorerNode node = tran.getSource();
		String destPath = tran.getDestPath();
		Message reMsg = new Message();
		reMsg.setName(Message.MOVE_RESPONSE_TRANSACTION);
		reMsg.put("transaction",tran);
		int result = processor.getServerManager().move(node, destPath);
		System.out.println();
		reMsg.setResult(result);
		if(result > 0)
			processor.getNetworkManager().broadcastMessage(reMsg);
		else
			con.sendMessage(reMsg);
	}
}